package com.base.get;

import java.net.URI;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class DoGETParam {

    public static void main(String[] args) throws Exception {

        // 创建Httpclient对象
        CloseableHttpClient httpclient = HttpClients.createDefault();

        // 定义请求的参数
        /*URI uri = new URIBuilder("http://manage.taotao.com/rest/content").setParameter("categoryId", "36")
                .setParameter("page", "1").setParameter("rows", "6").build();*/

        URI uri = new URIBuilder("http://japi.zto.cn/zto/api_utf8/commonOrder").setParameter("msg_type", "SEARCHBYCODE").
                setParameter("company_id", "1001").setParameter("data_digest", "uEPQPS3+Q7CrvWi71oFWQQ==").
                setParameter("data", "{\"orderCode\": [\"1234567\",\"123123123\",\"12312312312\"],\"sendId\": \"123456678\"}").build();
        
        
        
        
        System.out.println(uri);

        // 创建http GET请求
        HttpGet httpGet = new HttpGet(uri);

        CloseableHttpResponse response = null;
        try {
            // 执行请求
            response = httpclient.execute(httpGet);
            // 判断返回状态是否为200
            if (response.getStatusLine().getStatusCode() == 200) {
                String content = EntityUtils.toString(response.getEntity(), "UTF-8");
                System.out.println(content);
            }
        } finally {
            if (response != null) {
                response.close();
            }
            //相当于关闭浏览器
            //httpclient.close();
        }

    }

}
